package com.design.singlecase.student;

/**
 * 饿汉式单例，在类加载时创建一个对象
 */
public class Student {
    //饿汉式单例，在类加载时创建一个对象
    //1.初始化对象
    private static final Student student = new Student();

    //2.私有化构造函数
    private Student() {
    }

    //3.静态方式：获取实例对象
    public static Student getInstance() {
        if (student != null) {
            return student;
        }
        return null;
    }

    public static void main(String[] args) {
        //创建对象方法
        Student student = getInstance();
        student.hello();
    }

    //方法
    public void hello() {
        System.out.println("hello world!");
    }
}